'''
https://pypi.org/project/efficient-apriori/

from efficient_apriori import apriori
transactions = [('eggs', 'bacon', 'soup'),
                ('eggs', 'bacon', 'apple'),
                ('soup', 'bacon', 'banana')]
itemsets, rules = apriori(transactions, min_support=0.5,  min_confidence=1)
print(rules)  # [{eggs} -> {bacon}, {soup} -> {bacon}]
'''
from efficient_apriori import apriori
import pandas as pd

data_source = pd.read_excel("超市购物数据集.xlsx")

# 整理transactions
transactions = []
for item in data_source.groupby(by="订单ID"):
    transactions.append(tuple(item[1]["购物项"].values))
print(transactions[:5])
print("--------------")

# 调用算法
itemsets, rules = apriori(transactions, min_support=0.1, min_confidence=1)
print(rules[:5])

